<template>
	<view class="bods">
		
		<Setps v-if="num < 4" :num=num :headtitle='headtext' :tit='tit' />
		<!-- 基本信息 -->
		<Setup v-if="num==0" @modifyNum ="modifyNum" :list = "travelAppList" :travelTrip="travelTrip"/>
		<!-- 行程信息 -->
		<application v-if="num==1" @modifyNum ="modifyNum" :list = "travelAppList"/>
		<!-- 预算信息 -->
		<budget v-if="num==2" @modifyNum ="modifyNum" :list = "travelAppList"/>
		<!-- 详情信息 -->
		<submission v-if="num==3" @modifyNum ="modifyNum" :list = "travelAppList" :travelTrip="travelTrip"/>	
		<!-- 审批信息 -->
		<approval v-if="num==4" :billno= "billNo" />	
	</view>
</template>
      
<script>
	import Setps from '@/workspaces/tools/setps.vue';
	import Setup from './setup.vue';//基本信息
	import application from './application.vue';//行程计划
	import budget from './Budget.vue';//费用预算
	import submission from './submission.vue';//出差申请详情
	import approval from '../invest/approval.vue';//出差申请审批
	export default {
		components: {
			Setps,
			Setup,
			application,
			budget,
			submission,
			approval
		},
		data(){
			return{
				travelTrip:0,
				num: null,
				billNo: "",
				wfContext: {},
				tit: [{
						name: '信息变更'
					},
					{
						name: '行程变更'
					},
					{
						name: '费用明细'
					},
					{
						name: '确认提交'
					},
				],
				headtext:'出差变更',
				travelAppList:{}
			}
		},
		onLoad() {
			//获取流程页面的流程上下文[实用的流程信息从这里获取]
			this.wfContext = window.parent.myvm.wfContext;
			console.info(this.wfContext);
			if (this.wfContext.WorkflowInstinceState == 0 || this.wfContext.WorkflowInstinceState == 1 || this.wfContext.WorkflowInstinceState == 5) {
				let billno= this.wfContext.WorkflowInstinceState == 0 ? this.$route.query.billNo : this.wfContext.BusinessKey;
				this.applicationQuery(billno)
			} else {
				this.num= 4;
				this.billNo= this.wfContext.BusinessKey;
				this.applicationQuery(this.billNo)
			}
			this.$oaconfig.cityData.cityInfoList= [];
			this.$oaconfig.cityData.provinceNmCityList= [];
		},
		methods:{
			modifyNum(num,list){
				let _this = this;
				_this.num = num;
				_this.travelAppList = JSON.parse(JSON.stringify(list));
				uni.pageScrollTo({
				   scrollTop: 0,
				   duration: 100,
				});
			},
			applicationQuery(billsNo){
				let _this = this;
				_this.$lyRequest.get('/gateway/reim/mp/dbsap/busiTripmEntity/getBusiTripmForm.do',{
					billsNo: billsNo
				}).then(data=>{
					if(data.data.result == 1){
						_this.travelAppList=JSON.parse(JSON.stringify(data.data.rows));
						_this.num= 0;
						let empNoList = [];
						_this.travelAppList.busiTripRouteEntityList.forEach((item, index) => {
							empNoList.push({
								empNo: item.empNo,
								empNm: item.empNm,
							})
						});
						_this.travelAppList.empNoList =[];
						_this.travelAppList.empNoList = _this.ObjectDeduplication(empNoList);
						_this.travelTrip = 1;
						if( _this.travelAppList.isCancel){
							_this.travelAppList.isCancel ='0';
						}
						
					}
				})
			},
			ObjectDeduplication(tempArr) {
				for (let i = 0; i < tempArr.length; i++) {
					for (let j = i + 1; j < tempArr.length; j++) {
						if (tempArr[i].empNo == tempArr[j].empNo) {
							tempArr.splice(j, 1);
							j--;
						};
			 	};
				};
				return tempArr;
			},
		}
	}
</script>

<style>
</style>